﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using LastLandClient.Data;

using Up2Link.SegString;

namespace LastLandClient.Core.CmdInterpreter
{
    public class CCmdBuy : ICommandInterpreter
    {
        public void ExecuteCommand(string _cmd, string _args)
        {
            if (_args != null)
            {
                String[] args = _args.Split(CConst.DELIMITER_ARGUMENT);
                if (args.Length == 1 && CData.clientConnected)
                {
                    String arg = args[0].ToLowerInvariant().Trim();
                    Int32 msgCode = 0;
                    switch (arg)
                    {
                        case "melee":
                            msgCode = CConst.CLIENT_MESSAGE_BUY_MELEE;
                            break;
                        case "ranged":
                            msgCode = CConst.CLIENT_MESSAGE_BUY_RANGED;
                            break;
                        case "siege":
                            msgCode = CConst.CLIENT_MESSAGE_BUY_SIEGE;
                            break;
                        case "horse":
                            msgCode = CConst.CLIENT_MESSAGE_BUY_HORSE;
                            break;
                        case "armor":
                            msgCode = CConst.CLIENT_MESSAGE_BUY_ARMOR;
                            break;
                        case "shield":
                            msgCode = CConst.CLIENT_MESSAGE_BUY_SHIELD;
                            break;
                        case "tmelee":
                            msgCode = CConst.CLIENT_MESSAGE_BUY_TMELEE;
                            break;
                        case "tranged":
                            msgCode = CConst.CLIENT_MESSAGE_BUY_TRANGED;
                            break;
                        case "tsiege":
                            msgCode = CConst.CLIENT_MESSAGE_BUY_TSIEGE;
                            break;
                        case "tmounted":
                            msgCode = CConst.CLIENT_MESSAGE_BUY_TMOUNTED;
                            break;
                        case "tagriculture":
                            msgCode = CConst.CLIENT_MESSAGE_BUY_TAGRICULTURE;
                            break;
                        case "tindustry":
                            msgCode = CConst.CLIENT_MESSAGE_BUY_TINDUSTRY;
                            break;
                        case "tcommerce":
                            msgCode = CConst.CLIENT_MESSAGE_BUY_TCOMMERCE;
                            break;
                        case "tconstruction":
                            msgCode = CConst.CLIENT_MESSAGE_BUY_TCONSTRUCTION;
                            break;
                        default:
                            break;
                    }

                    if (msgCode != 0)
                    {
                        CMessageSS buyMsg = new CMessageSS(msgCode, 0, CMessageSS.ENCODING_UTF32, "");
                        CData.client.Send(buyMsg);
                    }
                    else
                    {
                        CData.console.SendOutput("参数" + arg + "无效");
                        CData.console.SendOutput("buy:melee|ranged|siege|horse|armor|shield|tmelee|tranged|tsiege|tmounted|tagriculture|tindustry|tcommerce|tconstruction");
                    }
                }
                else if (args.Length != 1)
                {
                    CData.console.SendOutput("buy指令接受一个参数");
                }
                else if (!CData.clientConnected)
                {
                    CData.console.SendOutput("玩家尚未连接服务器");
                }
                else
                {
                    CData.console.SendOutput("无效的指令");
                }
            }
            else
            {
                CData.console.SendOutput("无效的指令");
            }
        }
    }
}
